<template>

  <el-table :data="tableData" style="width: 100%" >
    <el-table-column type="index" label="序号" width="120" />
    <el-table-column label="图片">
      <template #default="scope">
        <img :src="scope.row.img1" width="60" alt="">
      </template>
    </el-table-column>
    <el-table-column label="名称" prop="proname" width="180" />
    <el-table-column label="分类" prop="category" />
    <el-table-column label="原价" prop="originprice" />
    <el-table-column label="折扣" prop="discount" />
    <el-table-column label="销量" prop="sales" width="180"/>
    <el-table-column label="是否售卖" width="180">
      <template #default="scope">
        <el-switch v-model="scope.row.issale" />
      </template>
    </el-table-column>
    <el-table-column label="是否秒杀" width="180">
      <template #default="scope">
        <el-switch v-model="scope.row.isseckill" />
      </template>
    </el-table-column>
    <el-table-column label="是否推荐" width="180">
      <template #default="scope">
        <el-switch v-model="scope.row.isrecommend" />
      </template>
    </el-table-column>
    <el-table-column label="操作" align="right">
      <template #default="scope">
        <el-button size="small" type="danger" @click="handleDelete(scope.$index)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <div class="demo-pagination-block">
    <div class="demonstration">All combined</div>
    <el-pagination
      v-model:current-page="currentPage4"
      v-model:page-size="pageSize4"
      :page-sizes="[100, 200, 300, 400]"
      :small="small"
      :disabled="disabled"
      :background="background"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue'
import { getProList } from '@/api/pro.js'

const sale = ref("")
const tableData = ref([])
onMounted(async () => {
  let res = await getProList('/pro/list',{
    count:1,
    limitNum:10
  })
  if (res.code == '200') {
    tableData.value = res.data.map(item => ({
      ...item,
      isseckill: Boolean(item.isseckill),
      isrecommend: Boolean(item.isrecommend),
      issale: Boolean(item.issale)
    }))
  }
})

// 修改
const handleEdit = (index, row) => {
}

const handleDelete =(index) => {
 tableData.value.splice(index,1)
}
</script>
